package com.sg.hms.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sg.hms.Model.Food;
import com.sg.hms.Model.Role;
import com.sg.hms.Service.FoodService;
import com.sg.hms.ServiceImpl.FoodServiceImpl;
/**
 * 
 * @author 张杨
 *
 */
public class SearchFoodController extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		  	doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		//PrintWriter pw  =resp.getWriter();
		FoodService fService=new FoodServiceImpl();
		HttpSession session=req.getSession();
		String searchName=req.getParameter("searchName");
		//System.out.println(searchName);
		Role role= (Role) session.getAttribute("currentrole");
		List<Food> foods=fService.findFood(role.getRoleId(), searchName);
		//pw.write(foods.toString());
		session.setAttribute("foods", foods);
		//for (Food food : foods) {
			//System.out.println(food.getfName()+food.getWeight()+food.getFoId());
		//}
		req.getRequestDispatcher("page/food.jsp").forward(req, resp);
		//resp.sendRedirect("main.jsp");
	//	resp.sendRedirect("");
	}
}
